package com.seadragon.app.ksr.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.seadragon.app.ksr.dao.OfficeDao;
import com.seadragon.app.ksr.model.Office;
import com.seadragon.app.ksr.model.Review;
import com.seadragon.app.ksr.service.OfficeService;
import com.seadragon.app.ksr.util.IndexManager;

@Service("officeService")
@Transactional
public class OfficeServiceImpl implements OfficeService {
	private Logger logger = LoggerFactory.getLogger(OfficeServiceImpl.class);
	@Autowired
	private OfficeDao officeDao;
	
	@Autowired
	private IndexManager indexManager;
	
	@Override
	public Office findById(long id) {
		return officeDao.findById(id);
	}
	
	@Override
	public Office update(Office office, Review review){
		try{
			indexManager.insertDocument(office);
			indexManager.insertDocument(review);
		}catch(Exception ex){
			logger.error(ex.getMessage(), ex);
		}
		return officeDao.update(office, review);
	}

	@Override
	public List<Office> findAll(int offset, int pageSize) {
		return officeDao.findAll(offset, pageSize);
	}
}
